/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import Bean.CekStokBarangPusat;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



@WebServlet(urlPatterns = {"/TambahStokPusat"})
public class TambahStokPusat extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            String jns = request.getParameter("jenis_brg");
            String nama = request.getParameter("nama_brg");
            String tgl = request.getParameter("date_brg");
            String jmlh = request.getParameter("jmlh_brg");

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date date = sdf.parse(tgl);
            CekStokBarangPusat ck = new CekStokBarangPusat();
            String kode = ck.generateKodeBarang(date, jns);
            String code = ck.kodeBarangFix(kode);
            ck.setKode_barang(code);
            ck.setNama_barang(nama);
            ck.setKode_kategori(jns);
            ck.setJumlah(jmlh);
            ck.tambahStockPusat(ck);

            out.println("<html>");
            out.println("<head>");
            out.println("<title>Status Tambah Stok Pusat Frogstone</title>");
            out.println("<link href=\"css/style_web.css\" rel=\"stylesheet\" type=\"text/css\"/>");
            out.println("</head>");
            out.println("<body id=\"home\">");
            out.println("<div id=\"wrapper\">");
            out.println("<div id=\"header\">");
            out.println("<div id=\"site_title\">");
            out.println("<a href=\"#\"></a>");
            out.println("</div>");
            out.println("<div id=\"header_kanan\">");
            out.println("</div>");
            out.println("<div id=\"content\">");
            out.println("<center>");
            out.println("<h2><b><font color=\"red\" face=\"Verdana\">STOK BERHASIL DI TAMBAH...!!!!</font></b></h2></br>");
            out.println("<form action=\"Admin/CekStokPusat.jsp\"><input type=\"submit\" name=\"submit\" value=\"LIHAT STOK\"/></form>");
            out.println("</center>");
            out.println("</div>");
            out.println("</div>");
            out.println("</div>");
            out.println("</body>");
            out.println("</html>");

        } catch (Exception e) {
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Status Tambah Stok Pusat Frogstone</title>");
            out.println("<link href=\"css/style_web.css\" rel=\"stylesheet\" type=\"text/css\"/>");
            out.println("</head>");
            out.println("<body id=\"home\">");
            out.println("<div id=\"wrapper\">");
            out.println("<div id=\"header\">");
            out.println("<div id=\"site_title\">");
            out.println("<a href=\"#\"></a>");
            out.println("</div>");
            out.println("<div id=\"header_kanan\">");
            out.println("</div>");
            out.println("<div id=\"content\">");
            out.println("<center>");
            out.println("<h2><b><font color=\"red\" face=\"Verdana\">STOK GAGAL DI TAMBAH...!!!!</font></b></h2></br>");
            out.println("<form action=\"Admin/TambahStokPusat.jsp\"><input type=\"submit\" name=\"submit\" value=\"ULANG PROSES\"/></form>");
            out.println("</center>");
            out.println("</div>");
            out.println("</div>");
            out.println("</div>");
            out.println("</body>");
            out.println("</html>");
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
